package com.stox.provider;

import java.util.Date;

import com.stox.model.Bar;
import com.stox.model.DataStream;
import com.stox.model.Exchange;
import com.stox.parser.DataStreamParser;

public abstract class AbstractDataProvider implements DataProvider {
	
	private String downloadRawData(Date date, Exchange exchange){
        	String downloadUri = constructBreadthUri(date);
    		return downloadRawData(downloadUri);
	}
	
	private DataStream parseRawData(String rawData, Date date, Exchange exchange){
		DataStream dataStream = getParser().parse(exchange, rawData);
        for(Bar bar : dataStream.getBars()){
        	bar.setDate(date);
        }
        return dataStream;
	}
	

	public DataStream get(Exchange exchange, Date date) {
		return parseRawData(downloadRawData(date, exchange), date, exchange);
	}
	
	public abstract DataStreamParser getParser();
	public abstract String constructBreadthUri(Date date);
	public abstract String downloadRawData(String uri);

}
